#include "stdafx.h"
#include "DepthStencilState.h"

namespace Reign
{namespace Video
{namespace D3D10
{
	#pragma region Properties
	D3D10_DEPTH_STENCIL_DESC* DepthStencilStateDesc::Desc::get() {return desc;}
	#pragma endregion

	#pragma region Constructors
	DepthStencilStateDesc::DepthStencilStateDesc(DepthStencilStateTypes type)
	{
		null();
		desc = new D3D10_DEPTH_STENCIL_DESC();
		switch (type)
		{
			case (DepthStencilStateTypes::None):
				desc->DepthEnable = false;
				desc->DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ZERO;
				desc->DepthFunc = D3D10_COMPARISON_ALWAYS;

				desc->StencilEnable = false;
				desc->StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
				desc->StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;

				desc->FrontFace.StencilFunc = D3D10_COMPARISON_NEVER;
				desc->FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
				desc->FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
				desc->FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
				
				desc->BackFace.StencilFunc = D3D10_COMPARISON_NEVER;
				desc->BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
				desc->BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
				desc->BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
				break;

			case (DepthStencilStateTypes::ReadWrite_Less):
				desc->DepthEnable = true;
				desc->DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
				desc->DepthFunc = D3D10_COMPARISON_LESS;

				desc->StencilEnable = false;
				desc->StencilReadMask = D3D10_DEFAULT_STENCIL_READ_MASK;
				desc->StencilWriteMask = D3D10_DEFAULT_STENCIL_WRITE_MASK;

				desc->FrontFace.StencilFunc = D3D10_COMPARISON_NEVER;
				desc->FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
				desc->FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
				desc->FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
				
				desc->BackFace.StencilFunc = D3D10_COMPARISON_NEVER;
				desc->BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
				desc->BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_KEEP;
				desc->BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
				break;

			default:
				Debug::ThrowError(L"DepthStencilStateDesc", L"Unsuported DepthStencilStateType");
				break;
		}
	}

	DepthStencilStateDesc::~DepthStencilStateDesc()
	{
		if (desc) delete desc;
		null();
	}

	void DepthStencilStateDesc::null()
	{
		desc = 0;
	}
	#pragma endregion
}
}
}